package com.leetcode.string;

public class AddStrings {
    public static void main(String[] args) {

    }

    public String addStrings(String num1, String num2) {
        String res = "";
        int len1 = num1.length();
        int len2 = num2.length();
        int i = len1 - 1;
        int j = len2 - 1;
        int high = 0;
        int low = 0;
        while (i >= 0 || j >= 0) {
            int tmp;
            if (i < 0) {
                tmp = (num2.charAt(j) - '0') + high;
            } else if (j < 0) {
                tmp = (num1.charAt(i) - '0') + high;
            } else {
                tmp = (num1.charAt(i) - '0') +
                        (num2.charAt(j) - '0') + high;
            }
            low = tmp % 10;
            high = tmp / 10;
            res = low + res;
            i--;
            j--;
        }
        if (high != 0) {
            res = high + res;
        }
        return res;
    }
}
